package blackstar.plugin.monitor.jvm;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;

import blackstar.agent.jvm.JMXProxy;
import blackstar.plugin.monitor.AbstractMonitor;

/**
 * @author Ray (ayufox@gmail.com)
 */
public class ThreadMonitor extends AbstractMonitor
{
	private ThreadMXBean threadMXBean;

	public ThreadMonitor()
	{
		super("thread");
	}

	protected void doInit(JMXProxy jmxProxy) throws Exception
	{
		this.threadMXBean = ManagementFactory.newPlatformMXBeanProxy(jmxProxy
				.getLocalMBeanServerConnection(),
				ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class);

	}

	protected void doOnTimeout() throws Exception
	{
		long data = threadMXBean.getThreadCount();
		report(data);
	}
}
